package com.myidis.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.myidis.entity.RightRole;
import com.myidis.servlet.RightRoleServlet;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/role")
@Api(tags = "角色管理接口")
public class RightRoleController {
	@Autowired
	private RightRoleServlet userRoleServlet;
	
	@ResponseBody
	@ApiOperation("获取所有角色的信息")
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public List<RightRole> list() {
		return userRoleServlet.all();
	}
	
	@ResponseBody
	@ApiOperation("获取一个角色的信息")
	@RequestMapping(value="/entity",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public RightRole one(@RequestBody RightRole role) {
		return userRoleServlet.getOne(role.getId());
	}
	
	@ResponseBody
	@ApiOperation("检查一个角色的权限？？？")
	@RequestMapping(value="/check",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public boolean check(@RequestBody RightRole role) {
		boolean res = userRoleServlet.check(role);
		System.out.println(res);
		return res;
	}
	
	@ResponseBody
	@ApiOperation("添加一个角色")
	@RequestMapping(value="/add",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int add(@RequestBody RightRole rightRole) {
		return userRoleServlet.insert(rightRole);
	}
	
	@ResponseBody
	@ApiOperation("添加一组角色")
	@RequestMapping(value="/addAll",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int addAll(@RequestBody List<RightRole> rightRoles) {
		return userRoleServlet.insertAll(rightRoles);
	}
	
	@ResponseBody
	@ApiOperation("修改一个角色")
	@RequestMapping(value="/upd",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int upd(@RequestBody RightRole rightRole) {
		return userRoleServlet.update(rightRole);
	}
 
	@ResponseBody
	@ApiOperation("删除一个角色")
	@RequestMapping(value="/del",method=RequestMethod.POST)
	public int del(@RequestBody int id) {
		return userRoleServlet.delete(id);
	}
	
	@ResponseBody
	@ApiOperation("删除一组角色")
	@RequestMapping(value="/delAll",method=RequestMethod.POST)
	public int delAll(@RequestBody int[] ids) {
		return userRoleServlet.deleteAll(ids);
	}
}
